{extend name="../../admin/view/main"}


{block name='content'}
<style>
    .layui-input {
        margin-top: 2px;
        margin-bottom: 10px;
    }
</style>
<form action="{:sysuri()}" class="layui-card layui-form" data-auto="true" method="post">
    <div class="layui-card-body">

        <label class="layui-form-item relative block">
            <span class="help-label"><b>政策标题</b></span>
            <input class="layui-input" name="title" placeholder="请输入政策标题" required value='{$vo.title|default=""}'>
        </label>

        <div class="layui-form-item" style="display: none">
            <span class="help-label"><b>政策类型</b></span>
            <div class="relative block">
                <input type="radio" name="type" value="1" {if ($vo.type ?? 1)== 1} checked {/if} label="资金">资金
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="type" value="2" {if ($vo.type ?? 1)== 2} checked {/if} label="人才">人才
            </div>
        </div>

        <div class="layui-form-item" style="display: none">
            <span class="help-label"><b>状态</b></span>
            <div class="relative block">
                <input type="radio" name="zhuangtai" value="1" {if ($vo.zhuangtai ?? 1)== 1} checked {/if} label="进行中">进行中
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="zhuangtai" value="2" {if ($vo.zhuangtai ?? 1)== 2} checked {/if} label="已完成">已完成
            </div>
        </div>

        <!--<div class="layui-form-item layui-col-xs12">-->
        <!--    <span class="help-label"><b>企业标签</b></span>-->
        <!--    <span class="color-desc margin-left-5"></span>-->
        <!--    <div id="peipeiList" class="xm-select-demo"></div>-->
        <!--    <input type="hidden" name="qybq" id="qybq" value="{$vo.qybq|default=''}">-->
        <!--</div>-->


        <!--<div class="layui-form-item">-->
        <!--    <span class="help-label"><b>企业列表</b></span>-->
        <!--    <span class="color-desc margin-left-5"></span>-->
        <!--    <div id="enterpriseList" class="xm-select-demo"></div>-->
        <!--    <input type="hidden" name="enterprises" id="enterprises" value="{$vo.enterprises|default=''}">-->
        <!--</div>-->

        <div class="layui-form-item" id="content-div">
            <span class="help-label"><b>基本信息</b></span>
            <div class="relative block">
                <textarea class="layui-hide" name="content" placeholder="请输入基本信息">{$vo.content|default=''}</textarea>
            </div>
        </div>


        <div class="layui-form-item">
            <span class="help-label"><b>兑付流程</b></span>
            <div class="relative block">
                <textarea class="layui-hide" name="duifu" placeholder="请输入兑付流程">{$vo.duifu|default=''}</textarea>
            </div>
        </div>


        <div class="layui-form-item " id="zcyw-div" style="">
            <span class="help-label"><b>政策原文</b></span>
            <div class="relative block">
                <textarea class="layui-hide" name="zcyw" placeholder="请输入政策原文">{$vo.zcyw|default=''}</textarea>
            </div>
        </div>


        <div class="layui-form-item relative" id="ctrq-div">
            <div style="float: left;min-width: auto;height: 38px;line-height: 38px;">
                <span class="help-label" style="padding-right: 40px;"><b>出台日期</b></span>
            </div>
            <div style="float: left;">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" name="ctrq" id="ctrq" required value="{$vo.ctrq|default=''}"
                           placeholder="请选择出台日期">
                </div>
            </div>
        </div>


        <!--<div class="layui-form-item relative" id="sbjzrq-div">-->
        <!--    <div style="float: left;min-width: auto;height: 38px;line-height: 38px;">-->
        <!--        <span class="help-label" style="padding-right: 40px;"><b>兑付日期</b></span>-->
        <!--    </div>-->
        <!--    <div style="float: left;">-->
        <!--        <div class="layui-input-inline">-->
        <!--            <input type="text" class="layui-input" name="sbjzrq" id="sbjzrq" required-->
        <!--                   value="{$vo.sbjzrq|default=''}" placeholder="请选择兑付日期">-->
        <!--        </div>-->
        <!--    </div>-->
        <!--</div>-->

        <div class="layui-form-item" style="display:none;">
            <span class="help-label"><b>政策文件</b></span>
            <div class="relative block label-required-null">
                <input class="layui-input think-bg-gray" name="wenjian_url" placeholder="请上传政策文件" readonly
                       value='{$vo.wenjian_url|default=""}'>
<!--                <a class="layui-icon layui-icon-upload input-right-icon" data-file="one" data-field="wenjian_url"-->
<!--                   data-type="docx,TXT,txt,doc,pptx,xlsx,xls,pdf"></a>-->
                <a class="layui-icon layui-icon-upload input-right-icon" data-file="one" data-field="wenjian_url"
                   data-type="pdf"></a>
            </div>
        </div>
        <div class="layui-form-item" style="display:none;">
            <span class="help-label"><b>政策拆解</b></span>
            <div id="policy-div">
                {if (isset($vo.policy))}
                {foreach $vo.policy as $policy}
                <input class="layui-input policy-input inline-block" data-id="" name="policy[]" value="{$policy}" title="">
                {/foreach}
                {else}
                <input class="layui-input policy-input inline-block" data-id="" name="policy[]" value="" title="">
                {/if}
            </div>
            <button class="layui-btn layui-btn-sm" type="button" onclick="addPolicy()">添加</button>
            <button type="button" class="layui-btn" onclick="delLastInput()">删除最后一个输入框</button>

        </div>

        <label class="layui-form-item relative block">
            <span class="help-label"><b>责任单位</b></span>
            <input class="layui-input" name="fbdw" placeholder="请输入责任单位" required value='{$vo.fbdw|default=""}'>
        </label>

        <div class="hr-line-dashed"></div>
        {notempty name='vo.id'}<input name='id' type='hidden' value='{$vo.id}'>{/notempty}

        <div class="layui-form-item text-center">
            <button class="layui-btn" type="submit">保存数据</button>
            <button class="layui-btn layui-btn-danger" data-history-back data-confirm="确定要取消编辑吗？" type='button'>
                取消编辑
            </button>
        </div>
    </div>

</form>
<script>
    function addPolicy() {
        var html = '<input class="layui-input policy-input" data-id="" name="policy[]" value="" title="">';
        $('#policy-div').append(html);
    }

    function delLastInput() {
        var inputContainer = $('#policy-div');
        // 获取最后一个 input 框
        var inputCount = inputContainer.find('.policy-input').length;
        var lastInput = inputContainer.find('.policy-input:last');
        // 如果存在则删除
        if (inputCount > 1) {
            lastInput.remove();
        } else {
            // 如果没有输入框，提示用户
            layer.msg('只剩下一个时不能删除！');
        }
    }

    layui.use(function () {
        var laydate = layui.laydate;
        // 渲染
        laydate.render({
            elem: '#ctrq'
        });
        laydate.render({
            elem: '#sbjzrq'
        });

    });
</script>


<script>

    require(['ckeditor'], function () {
        window.createEditor('[name=content]', {height: 350})
        window.createEditor('[name=duifu]', {height: 350})
        window.createEditor('[name=zcyw]', {height: 350})
    });


    $(function () {
        // getUserList();
        // getEnterpriseList();
    });

    function getUserList() {
        layui.use('xmSelect', function () {
            $.ajax({
                type: 'get',
                url: "{:url('getQybqList')}",
                data: "",
                dataType: "json",
                success: function (res) {
                    if (res.code) {
                        console.log(res);
                        var datas = [];
                        res.data.forEach(function (item) {
                            var uuid = "{$vo.qybq|default=''}".split(',');
                            if (uuid.length && uuid.findIndex(it => it == item.id) != -1) {
                                datas.push({name: item.name, value: item.id, selected: true});

                            } else {
                                datas.push({name: item.name, value: item.id});
                            }
                        });
                        xmSelect.render({
                            el: '#peipeiList',
                            tips: '请选择企业标签',//选项提示文字
                            filterable: true,//搜索模式
                            data: datas,
                            on: function (data) {
                                var selectArr = data.arr;
                                var seachArr = [];
                                for (var j = 0; j < selectArr.length; j++) {
                                    seachArr.push(selectArr[j].value)
                                }
                                $("#qybq").val(seachArr.toString());
                                getEnterpriseList(seachArr.toString());
                            }
                        })

                    } else {
                        console.log(res.info);
                    }
                },
                error: function (err) {
                    console.log(err)
                }
            });
        });
    }

    function getEnterpriseList() {
        var tag = $("#qybq").val();
        layui.use('xmSelect', function () {
            $.ajax({
                type: 'get',
                url: "/data/user.qiyebiaoqian/getEnterpriseList.html?tag=" + tag,
                data: "",
                dataType: "json",
                success: function (res) {
                    if (res.code) {
                        var datas = [];
                        res.data.forEach(function (item) {
                            datas.push({name: item.qymc, value: item.id, selected: true});
                        });
                        xmSelect.render({
                            el: '#enterpriseList',
                            tips: '请选择企业',//选项提示文字
                            filterable: true,//搜索模式
                            data: datas,
                            on: function (data) {
                                var selectArr = data.arr;
                                var seachArr = [];
                                for (var j = 0; j < selectArr.length; j++) {
                                    seachArr.push(selectArr[j].value)
                                }
                                console.log(seachArr.toString(), '------777777');
                                $("#enterprises").val(seachArr.toString());
                            }
                        })
                    } else {
                        console.log(res.info);
                    }
                },
                error: function (err) {
                    console.log(err)
                }
            });
        });
    }

</script>
{/block}
